home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 January
/
Macworld (1998-01).dmg
/
Shareware World
/
Comms & Internet
/
HTML mode 2.0 etc.
/
hctsmslMenu.tcl
< prev
next >
Wrap
Text File
|
1997-09-22
|
14KB
|
390 lines
## -*-Tcl-*-
# ###################################################################
# HTML and CSS mode - tools for editing Cascading Style Sheets
#
# FILE: "hctsmslMenu.tcl"
# created: 97-03-01 17.33.59
# last update: 97-09-20 19.43.34
# Author: Johan Linde
# E-mail: <jl@theophys.kth.se>
# www: <http://bach.theophys.kth.se/~jl/Alpha.html>
#
# Version: 2.0 and 1.0
#
# Copyright 1996, 1997 by Johan Linde
#
# This software may be used freely, and distributed freely, as long as the
# receiver is not obligated in any way by receiving it.
#
# If you make improvements to this file, please share them!
#
# ###################################################################
##
proc hctsmslMenu.tcl {} {}
# Variables defining submenus.
set htmlStyleSub {{"" Style STYLE} {"" Span SPAN} "(-" {"" "Import…"} {"" Font} {"" Color}
{"" Background} {"" Text} {"" Margin}
{"" Padding} {"" Border} {"" "Border Width"} {"" "Border Style"}
{"" "Border Color"} {"" Size} {"" Float}
{"" Clear} {"" Display} {"" "List Style"}}
set htmlHeadersSub {{"<B<O/1" "Header1/H1 no attr" H1}
{"<B<O/2" "Header2/H2 no attr" H2}
{"<B<O/3" "Header3/H3 no attr" H3}
{"<B<O/4" "Header4/H4 no attr" H4}
{"<B<O/5" "Header5/H5 no attr" H5}
{"<B<O/6" "Header6/H6 no attr" H6}}
set htmlBlocksSub {{"" "Insert Line Breaks/Remove Line Breaks"}
{"" "Insert Paragraphs"} "(-"
{"<U/b" "Paragraph/P no attr" P}
{"<U<O/b" "Division" DIV}
{"<B<O/Q" "Block Quote" BLOCKQUOTE} {"<B<O/S" "Address" ADDRESS}
{"<B<O/C" "Center" CENTER} {"<B<O/P" "Preformatted" PRE}
{"<B<O/X" "Multi Column" MULTICOL}
{"<B<O/Z" "Spacing" SPACER} "(-"
{"<O/b" "Line Break/BR no attr" BR}
{"<B<O/H" "Horizontal Rule/HR no attr" HR}
{"<B<O/B" "No Line Break" NOBR} {"<B<O/W" "Word Break" WBR}}
set htmlStylesSub {{"<B<I/F" Font FONT} {"<B<I/N" Basefont BASEFONT}
{"" Marquee MARQUEE} "(-" {"<B<I/B" Bold B}
{"<B<I/I" Italic I} {"<B<I/-" "Strike out" STRIKE} {"<B<I<O/-" Underlined U}
{"<B<I/." Superscript SUP} {"<B<I/," Subscript SUB} {"<B<I<O/." Bigger BIG}
{"<B<I<O/," Smaller SMALL} {"<B<I/T" Typewriter TT} {"<B<I/Z" Blinking BLINK}
"(-" {"<B<I/E" Emphasis EM} {"<B<I/S" Strong STRONG} {"<B<I/D" Definition DFN}
{"<B<I/C" Code CODE} {"<B<I/V" Variable VAR} {"<B<I/X" Citation CITE}
{"<B<I/K" Keyboard KBD} {"<B<I/P" Sample SAMP}}
set htmlLinksSub {{"<B<O/A" "Link or Anchor" A} {"<B<O/I" Image IMG}
{"" Object OBJECT} {"" Sound BGSOUND}}
set htmlPlug-insSub {{"<B<O/E" General EMBED} {"" LiveAudio EMBED}
{"" LiveVideo EMBED} {"" "QuickTime Movie" EMBED}
{"" "QuickTime VR" EMBED} {"" RealAudio EMBED} "(-" {"<B<O/N" "No Embed" NOEMBED}}
set htmlListsSub {{"" "Make List…"} "(-" {"<B<O/U" "Bulleted/UL no attr" UL}
{"<B<I/U" "New Bulleted Item"}
{"<B<O/O" "Numbered/OL no attr" OL}
{"<B<I/O" "New Numbered Item"} {"<B<O/D" "Directory" DIR}
{"<B<O/M" "Menu" MENU} {"<B<I/L" "New List Item" LI} "(-"
{"<B<U<O/D" "Discursive" DL} {"<B<I<O/L" "New Discursive Entry"}}
set htmlFormsSub {{"<B<U/F" Form FORM} "(-" {"<B<U/T" Text INPUT}
{"<B<U/B" Checkbox INPUT} {"<B<U/N" Button INPUT}
{"<B<U/R" Radio INPUT} {"<B<U/S" Submit INPUT}
{"<B<U/C" Reset INPUT} {"<B<U/P" Password INPUT}
{"<B<U/H" Hidden INPUT} {"<B<U/I" Image INPUT}
{"<B<U/U" "File Upload" INPUT}
"(-" {"<B<U<I/S" Select SELECT} {"<B<U/O" Option OPTION}
{"<B<U<I/T" Textarea TEXTAREA} {"" "Key Generator" KEYGEN}}
set htmlTablesSub {{"" "Table Template…"} {"" "Tabs to Rows…/Rows to Tabs"} {"" "Import Table…"} "(-"
{"<U<O/T" Table TABLE} {"<U<O/R" "Row/TR no attr" TR}
{"<U<O/H" "Header/TH no attr" TH} {"<U<O/D" "Cell/TD no attr" TD}
{"<U<O/C" Caption CAPTION} "(-"
{"" Head THEAD} {"" Body TBODY} {"" Foot TFOOT}
"(-" {"" "Column Group" COLGROUP} {"" "Column" COL}}
set htmlFramesSub {{"<B<U<I/F" "New Doc. with Frames…"} "(-" {"<B<U<I/O" Frameset FRAMESET}
{"<B<U<I/R" Frame FRAME} {"" "Inline Frame" IFRAME}
{"<B<U<I/N" "No Frames" NOFRAMES}}
set htmlImageSub {{"" "Convert NCSA Map…"} {"" "Convert CERN Map…"} "(-" {"<B<U/M" Map MAP}
{"<B<U/A" Area AREA}}
set htmlJavaSub {{"<U<I<O/J" Applet APPLET} {"<U<I<O/P" Parameter PARAM}
"(-" {"<U<I<O/S" Script SCRIPT} {"<U<I<O/N" "No Script" NOSCRIPT}}
set htmlLayersSub {{"" Layer LAYER} {"" "Inline Layer" ILAYER} {"" "No Layer" NOLAYER}}
set htmlOtherSub {{"<B<U<I/C" Comment} {"<B<U<I/B" Base BASE}
{"<B<U<I/I" Isindex ISINDEX}
{"<B<U<I/L" Link LINK} {"<B<U<I/M" Meta META} {"" "Comment Line"}}
set htmlSubMenus {HTML Browsers Packages Preferences
{Style Sheets} Headers {Blocks and Dividers} Styles Links
Plug-ins Lists Forms Tables Frames {Image Maps} {Java and JavaScript} Layers Other}
# Index of which menu is the first with HTML elements.
set htmlStartElements 4
# Returns a list defining a submenu.
proc htmlBuildOneMenu {me} {
global htmlMenuKey
set me0 [lindex $me 0]
global html${me0}Sub
# CSS menu share with Style menu
if {$me0 == "CSS"} {set me0 Style}
set tmp ""
foreach it [set html[lindex $me 0]Sub] {
if {$it == "(-"} {lappend tmp $it; continue}
if {[info exists htmlMenuKey(${me0}/[lindex $it 1])]} {
set key $htmlMenuKey(${me0}/[lindex $it 1])
} else {
set key [lindex $it 0]
}
set it2 [split [lindex $it 1] /]
if {[llength $it2] == 1} {
lappend tmp "$key[lindex $it2 0]"
} elseif {$key != ""} {
lappend tmp "<S$key[lindex $it2 0]" "<S<I$key[lindex $it2 1]"
} else {
lappend tmp "<S$key[lindex $it2 1]" "<S$key[lindex $it2 0]"
}
}
return $tmp
}
# Rebuilds a submenu.
proc htmlRebuildOneMenu {me {deleteCache 0}} {
set meny [htmlBuildOneMenu [lindex $me 0]]
menu -M HTML -p htmlMenuItem -m -n $me $meny
if {[info commands "html[lindex $me 0]MenuExtra"] != ""} {
eval html[lindex $me 0]MenuExtra
}
if {$deleteCache} {
htmlDeleteCache "HTML menu cache"
htmlDeleteCache "HTML Utilities menu cache"
}
htmlDisMark
htmlUtilDisMark
}
proc htmlReadMenuKeys {} {
global PREFS
if {[file exists "$PREFS:HTML:Menu key bindings"]} {
catch {uplevel #0 [list source "$PREFS:HTML:Menu key bindings"]}
}
}
proc htmlWriteMenuKeys {} {
global PREFS htmlMenuKey
if {![info exists htmlMenuKey]} {return}
message "Saving custom key bindings…"
foreach m [array names htmlMenuKey] {
lappend txt "set htmlMenuKey(\[list $m\]) [list $htmlMenuKey($m)]"
}
if {![file exists $PREFS]} {mkdir $PREFS}
if {![file exists $PREFS:HTML]} {mkdir $PREFS:HTML}
set fid [open "$PREFS:HTML:Menu key bindings" w]
puts $fid [join $txt \n]
close $fid
unset htmlMenuKey
}
#===============================================================================
# Custom Key Bindings
#===============================================================================
proc htmlKeyBindings {} {
global htmlSubMenus htmlUtilSubMenus htmlMenuKey
set ret ""
set rebuildHTML 0
set rebuildUtils 0
set rebuildCSS 0
set somethingModified 0
htmlReadMenuKeys
while {$ret != "Done" && ![catch {listpick -p "Choose a submenu to change key bindings in" [lsort [concat $htmlSubMenus $htmlUtilSubMenus]]} meny] && $meny != ""} {
set ret [htmlSetKeysInMenu $meny]
}
if {$somethingModified} {htmlWriteMenuKeys}
if {$rebuildHTML} {htmlRebuildMenu "Rebuilding HTML menu…"; message "Done."}
if {$rebuildUtils} {htmlRebuildUtilsMenu "Rebuilding HTML Utilities menu…"; message "Done."}
if {$rebuildCSS} {cssRebuildMenu}
catch {unset htmlMenuKey}
}
# Redefine key bindings in one submenu.
proc htmlSetKeysInMenu {meny} {
global htmlMenuKey htmlModeIsLoaded cssModeIsLoaded
set funcKeys {Enter Return Tab "Num Lock" F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15
Help Delete "Fwd Del" Home End "Page Up" "Page Down"}
set meny0 [lindex $meny 0]
global html${meny0}Sub
# CSS menu share with Style menu
if {$meny0 == "CSS"} {set meny0 Style}
set items [set html[lindex $meny 0]Sub]
regsub -all {\"\(-\"} $items "" items
foreach it $items {
if {[info exists htmlMenuKey(${meny0}/[lindex $it 1])]} {
set tmpKeys([lindex $it 1]) $htmlMenuKey(${meny0}/[lindex $it 1])
} else {
set tmpKeys([lindex $it 1]) [lindex $it 0]
}
}
set modified ""
while {1} {
# Build dialog.
set box ""
set h 30
foreach it $items {
if {$it == "(-"} {continue}
set key $tmpKeys([lindex $it 1])
set key1 ""
if {[regexp {<B} $key]} {append key1 "ctrl-"}
if {[regexp {<U} $key]} {append key1 "shift-"}
if {[regexp {<I} $key]} {append key1 "opt-"}
if {[regexp {<O} $key]} {append key1 "cmd-"}
if {[regexp {/(.)} $key a b]} {
if {[string compare $b a] == -1 || [string compare $b z] == 1} {
append key1 $b
} else {
append key1 [lindex $funcKeys [expr [htmlAscii $b] - 97]]
}
}
set it2 [split [lindex $it 1] /]
if {[llength $it2] == 1} {
lappend box -t [lindex $it2 0] 65 $h 205 [expr $h + 15] -t $key1 210 $h 370 [expr $h + 15]
lappend box -b Set… 10 $h 55 [expr $h + 15]
incr h 17
} elseif {$key1 != ""} {
lappend box -t [lindex $it2 0] 65 $h 205 [expr $h + 15] -t $key1 210 $h 370 [expr $h + 15]
lappend box -b Set… 10 [expr $h + 8] 55 [expr $h + 23]
incr h 17
regsub {((ctrl-)?(shift-)?)(.*)} $key1 {\1opt-\4} key1
lappend box -t [lindex $it2 1] 65 $h 205 [expr $h + 15] -t $key1 210 $h 370 [expr $h + 15]
incr h 17
} else {
lappend box -t [lindex $it2 0] 65 $h 205 [expr $h + 15]
lappend box -b Set… 10 [expr $h + 8] 55 [expr $h + 23]
incr h 17
lappend box -t [lindex $it2 1] 65 $h 205 [expr $h + 15]
incr h 17
}
}
if {$meny == "CSS"} {
set buttons "-b OK 20 [expr $h + 10] 85 [expr $h + 30] -b Cancel 105 [expr $h + 10] 170 [expr $h + 30]"
set cancel 1
} else {
set buttons "-b Continue 20 [expr $h + 10] 85 [expr $h + 30] -b Done 105 [expr $h + 10] 170 [expr $h + 30] \
-b Cancel 190 [expr $h + 10] 255 [expr $h + 30]"
set cancel 2
}
set values [eval [concat dialog -w 380 -h [expr $h + 40] \
$buttons -t [list $meny] 50 10 250 25 $box]]
if {[lindex $values $cancel]} {
# Cancel
return "Done"
} elseif {[lindex $values 0] || [lindex $values 1]} {
# Continue or Done
# Save new key bindings
foreach it $modified {
set htmlMenuKey(${meny0}/$it) $tmpKeys($it)
}
htmlDeleteCache "CSS keybindings cache"
if {[llength $modified]} {
uplevel 1 {set somethingModified 1}
switch $meny {
HTML {uplevel 1 {set rebuildHTML 1}}
Utilities {uplevel 1 {set rebuildUtils 1}}
"Style Sheets" {
# Rebuild both Style sheet menu and CSS menu
htmlDeleteCache "CSS menu cache"
htmlRebuildOneMenu "Style Sheets" 1
if {[info exists cssModeIsLoaded]} {uplevel 1 {set rebuildCSS 1}}
}
CSS {
# Rebuild both Style sheet menu and CSS menu
if {[info exists htmlModeIsLoaded]} {
htmlRebuildOneMenu "Style Sheets" 1
} else {
htmlDeleteCache "HTML menu cache"
}
uplevel 1 {set rebuildCSS 1}
}
default {
htmlRebuildOneMenu $meny 1
# Redefine key bindinds in CSS mode.
if {[info exists cssModeIsLoaded]} {
foreach k [array names oldKeys] {
lappend re [list $k $oldKeys($k) $tmpKeys($k)]
cssReBindKey $meny0 $re
}
}
}
}
}
if {[lindex $values 1]} {return "Done"}
return
} else {
# Get a new key.
set it [lindex [lindex $items [expr [lsearch $values 1] - 1 - $cancel]] 1]
if {![catch {htmlGetAKey $it $tmpKeys($it)} newKey] && $newKey != $tmpKeys($it)} {
set oldKeys($it) $tmpKeys($it)
set tmpKeys($it) $newKey
lappend modified $it
}
}
}
}
# Ask for a key binding for a menu item.
proc htmlGetAKey {elem keystr} {
set funcKeys {Enter Return Tab "Num Lock" F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15
Help Delete "Fwd Del" Home End "Page Up" "Page Down"}
set option [expr ![regexp {/} $elem]]
if {[string length $keystr]} {
set values "0 0"
set key [string range $keystr [expr [string length $keystr] - 1] end]
if {[string compare $key a] == -1 || [string compare $key z] == 1} {
lappend values "Normal key"
set mkey $key
} else {
lappend values [lindex $funcKeys [expr [htmlAscii $key] - 97]]
set mkey {}
}
lappend values [regexp {<U} $keystr]
lappend values [regexp {<B} $keystr]
if {$option} {lappend values [regexp {<I} $keystr]}
lappend values [regexp {<O} $keystr]
lappend values $mkey
} else {
set values {0 0 "Normal key"}
}
while {1} {
set box "-t {Key binding for '$elem'} 10 10 315 25 \
-t Key 10 40 40 55 \
-m [list [concat [list [lindex $values 2]] [list "<No binding>" "Normal key"] $funcKeys]] 80 40 250 55 \
-c Shift [list [lindex $values 3]] 10 70 60 85 \
-c Control [list [lindex $values 4]] 80 70 150 85"
if {$option} {lappend box -c Option [lindex $values 5] 160 70 220 85}
lappend box -c Command [lindex $values [expr 5 + $option]] 230 70 315 85
lappend box -n "Normal key" -e [lindex $values [expr 6 + $option]] 50 40 70 55
set values [eval [concat dialog -w 320 -h 130 \
-b OK 20 100 85 120 -b Cancel 105 100 170 120 $box]]
if {[lindex $values 1]} {error "Cancel"}
set elemKey [string toupper [string trim [lindex $values [expr 6 + $option]]]]
set special [lindex $values 2]
set keyStr ""
if {[lindex $values 3]} {append keyStr "<U"}
if {[lindex $values 4]} {append keyStr "<B"}
if {$option && [lindex $values 5]} {append keyStr "<I"}
if {[lindex $values [expr 5 + $option]]} {append keyStr "<O"}
if {$special == "<No binding>"} {break}
if {[string length $elemKey] > 1 && $special == "Normal key"} {
alertnote "You should only give one character for key binding."
} elseif {$special == "Normal key" && [htmlAscii $elemKey] > 126} {
alertnote "Sorry, can't define a key binding with $elemKey."
} elseif {$elemKey != "" && $special == "Normal key" && ($keyStr == "" || $keyStr == "<U")} {
alertnote "You must choose at least one of the modifiers control, option and command."
} elseif {![regexp {F[0-9]} $special] && $special != "Tab" && $special != "Normal key" && $keyStr == ""} {
alertnote "You must choose at least one modifier."
} else {
break
}
}
if {$special == "<No binding>"} {set elemKey ""}
if {$special != "Normal key" && $special != "<No binding>"} {set elemKey [htmlAscii [expr [lsearch -exact $funcKeys $special] + 97] 1]}
if {![string length $elemKey]} {
set keyStr ""
} else {
append keyStr "/$elemKey"
}
return $keyStr
}